/*
 * Created by JFormDesigner on Sun Oct 19 19:32:52 CST 2025
 */

package com.geek.javase.ch10.jformdesigntest.other;

import java.awt.*;
import java.net.URL;
import javax.swing.*;

/**
 * @author 27636
 */
public class MyImage extends JFrame {
    public static void main(String[] args) {
        new MyImage().setVisible(true);
    }
    public MyImage() {
        initComponents();
        //设置图片方式1：
        //按钮设置图片
        URL url = MyImage.class.getResource("flowerTest.png");
        button1.setIcon(new ImageIcon(url));
        //设置图片方式2：
        //直接从画板界面icon找到路径

        //不建议使用绝对路径
        //button1.setIcon(new ImageIcon("D:\\CodeFile\\igeeklearn\\testJavaSE\\src\\com\\geek\\javase\\ch10\\jframetest\\other\\flowerTest.png"));
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        label1 = new JLabel();
        button1 = new JButton();

        //======== this ========
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        Container contentPane = getContentPane();
        contentPane.setLayout(new BorderLayout());

        //---- label1 ----
        label1.setText("text");
        label1.setIcon(new ImageIcon(getClass().getResource("/com/geek/javase/ch10/jframetest/other/dogTest.png")));
        contentPane.add(label1, BorderLayout.CENTER);

        //---- button1 ----
        button1.setText("text");
        button1.setIcon(new ImageIcon(getClass().getResource("/com/geek/javase/ch10/jframetest/other/flowerTest.png")));
        contentPane.add(button1, BorderLayout.SOUTH);
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JLabel label1;
    private JButton button1;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
